package com.guguskins.back.config;

import com.guguskins.back.common.constant.RabbitMQConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class RabbitMQConfig {

    @Bean
    public Queue emailQueue() {
        return new Queue("email_guguskins_queue", true);
    }


    @Bean
    public CustomExchange rollDelayExchange() {
        Map<String, Object> args = new HashMap<>(1);
        args.put("x-delayed-type", "direct");
        return new CustomExchange(RabbitMQConstant.Exchange.ROLL_DELAY, "x-delayed-message", true, false, args);
    }

    @Bean
    public Queue rollDelayQueue() {
        return new Queue(RabbitMQConstant.Queue.ROLL_DELAY, true);
    }

    @Bean
    public Binding rollDelayBinding() {
        return BindingBuilder.bind(rollDelayQueue()).to(rollDelayExchange()).with(RabbitMQConstant.RoutingKey.ROLL_DELAY).noargs();
    }


    @Bean
    public CustomExchange incubationDelayExchange() {
        Map<String, Object> args = new HashMap<>(1);
        args.put("x-delayed-type", "direct");
        return new CustomExchange(RabbitMQConstant.Exchange.ROLL_DELAY, "x-delayed-message", true, false, args);
    }

    @Bean
    public Queue incubationDelayQueue() {
        return new Queue(RabbitMQConstant.Queue.ROLL_DELAY, true);
    }

    @Bean
    public Binding incubationDelayBinding() {
        return BindingBuilder.bind(rollDelayQueue()).to(rollDelayExchange()).with(RabbitMQConstant.RoutingKey.ROLL_DELAY).noargs();
    }
}
